package com.bigdata.spark.core.acc

import org.apache.spark.{SparkConf, SparkContext}

object Acc01 {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local").setAppName("Acc")
    val sc = new SparkContext(sparkConf)

    // TODO 累加器：分布式共享只写变量
    val rdd = sc.makeRDD(List(1, 2, 3, 4))

    // reduce : 分区内计算，分区间计算
    //val i = rdd.reduce(_ + _)
    //println(i)

    var sum = 0
    rdd.foreach(
      num => {
        sum += num
      }
    )
    println("sum = "+sum)     // sum = 0


    sc.stop()
  }
}
